@echo off

rem **
rem * Library
rem * by XERO
rem *


rem ** 
rem * Load the configuration
rem *
call .\config.bat
goto %1


rem **
rem * Make a directory if it doesn't exist and return its full path
rem * %1 [in] Relative path to a file or directory.
rem *         Assume basename is a file if it doesn't exist.
rem * %2 [out] Fully qualified path to file or directory
rem *
:md_and_get_full_path
setlocal
set folder=%~dp1
if not exist "%folder%" md "%folder%"
pushd "%folder%"
set folder=%CD%
popd
endlocal & set "%2=%~f1"
goto :eof


rem **
rem * Execute SQL statements from a file
rem * %2 [in] The name of the SQL file. The file must be in the /sql folder
rem * %3 [in] The log file to generate
rem *
:db_exec
setlocal
call :md_and_get_full_path "..\logs\%~3" log
pushd "..\sql"
call :db_login <"%~nx2" >"%log%" 2>&1
popd
endlocal
goto :eof


rem **
rem * Database login
rem *
:db_login
mysql --host=%db_host% --user=%db_user% --password=%db_password%
goto :eof